import configparser
import argparse
import ssl
import pymisp
from pymisp import PyMISP, ExpandedPyMISP
from pymisp.tools import make_binary_objects

CFG = configparser.ConfigParser()
CFG.read('config.ini')
ssl._create_default_https_context = ssl._create_unverified_context


def init(url, key):
    return ExpandedPyMISP(url, key, ssl=False)


ATTACHMENT_PATH = "/home/samsung/Projects/AT-CTI/unittest/data/duplicate-dns-requests.pcap"
misp = init(url=CFG['misp']['url'], key=CFG['misp']['key'])


# Query events
# event = mispconn.get_event(1)
# print(event)


# Upload malware sample
# fo, peo, seos = make_binary_objects('duplicate-dns-requests.pcap')
# print(fo, peo, seos)
# response = mispconn.add_object(1, fo, pythonify=True)
# for ref in fo.ObjectReference:
#                 r = mispconn.add_object_reference(ref)


# Upload general attachments along with creating a new event
a = pymisp.MISPAttribute()
describe_types = misp.describe_types_local
describe_types['sane_defaults']['malware-sample']['default_category'] = 'External analysis'
a.type = 'attachment'
a.value = 'duplicate-dns-requests.pcap'
a.data = ATTACHMENT_PATH
a.comment = 'Test uploading attachment'

m = pymisp.MISPEvent()
m.info = 'Test uploading attachment'
m.attributes = [a]
misp.add_event(m)
m.add_attribute()


#
# class Test:
#     def __init__(self):
#         self._age = None
#
#     @property  # 将age转换为属性，并为其赋能装饰器@age.setter
#     def age(self) -> int:
#         return self._age
#
#     @age.setter
#     def age(self, value: int):
#         if 1 <= value <= 200:
#             self._age = value
#         else:
#             raise RuntimeError("test")
#
#
# test = Test()
# test.age=300
# print(test.age)